package com.fl.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;


@Configuration
public class RabbitMQConfig {

    private static String direct_queue = "direct.pay.queue";
    private static String exchange = "direct.pay.exchange";
    private static String dead_exchange = "dead_exchange";
    private static String dead_routing_key = "DelayKey";
    private static String routing_key = "routing_key";

    @Bean
    public Queue directQueue(){
        Map<String,Object> args = new HashMap<>(3);
        args.put("x-dead-letter-exchange",dead_exchange);
        args.put("x-dead-letter-routing-key",dead_routing_key);
        //10秒过期
        args.put("x-message-ttl",10000);
        //队列名 是否持久化 是否独占队列 是否自动删除 其他规则
        return new Queue(direct_queue,true,false,false,args);
    }

    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange(exchange);
    }


    @Bean
    public Binding binding(){
        return BindingBuilder.bind(directQueue()).to(directExchange()).with(routing_key);
    }



}
